#pragma once

#include <connmgr.h>
#include <connmgr_proxy.h>

#include "Config.h"

//#define  _GET_FILE_BY_URL_

static HANDLE m_hConnection = NULL;


#define BSTR_TO_STRING(b,s,n)  	\
	WideCharToMultiByte(CP_ACP,0,b,-1,s,n,NULL,NULL)

#define STRING_TO_BSTR(s,b,n)   \
	MultiByteToWideChar(CP_ACP,0,s,-1,b,n);   


class CContosrv
{
public:
	CContosrv(CConfig* config);
	~CContosrv(void);

	int GetUserList(char* userName = NULL);
	int GetMediaList(char* userName = NULL);
	int GetMediaFile(char* userName, char* filename, char* tagFile=NULL);
	BOOL UploadMediaFile(char* filePathName,char* userName,char* fileName);

	int DownloadFileByUrl (TCHAR *szUrl,CHAR *szFileName);
	BOOL GetInternetFile (LPTSTR lpszServer, LPTSTR lpszProxyServer, bool bProxy=false,bool bOpenURL=false);
private:
	//BOOL GetMediaFile();
	BOOL UploadFile(char* ip, int port,char* upFile,int cmd,char* para1=NULL,char* para2 = NULL);
	int DownloadFile(char* szServer,char* szFileName,int cmd,char* para1=NULL,char* para2 = NULL);

private:
	void DisconnectInternet();
	HRESULT TryConnectInternet(DWORD dwTimeout, HANDLE* phConnection);
	BOOL GetProxyServer( HANDLE hConnection, char* pszProxyServer );

	BOOL InitNetEnv();
	void ReleaseNetEnv();
private:
	BOOL m_nNetEvnInited;

	CConfig* m_Config;
	
};
